package net.qhzw.geologr5.gis.service.system.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import net.qhzw.geologr5.gis.common.framework.utils.JsonResult;
import net.qhzw.geologr5.gis.service.system.exceltem.PointDrillingInfoExcel;
import net.qhzw.geologr5.gis.service.system.query.ProjectPointQuery;
import net.qhzw.geologr5.gis.service.system.service.ProjectPointService;
import net.qhzw.geologr5.gis.service.system.vo.project.Point;
import net.qhzw.geologr5.gis.service.system.vo.project.PointDrillingInfoVo;
import net.qhzw.geologr5.gis.service.system.vo.project.PointProbeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


/***
 * 项目点位前端控制器
 */

@RestController
@RequestMapping("projectPoint")
public class ProjectPointController {

    @Autowired
    private ProjectPointService projectPointService;


    /***
     * 项目点位 新增修改
     * @return
     */
    @PostMapping("create")
    public JsonResult create(Point point, PointDrillingInfoVo drillingInfoVo,
                             PointProbeInfo probeInfo) {
        return projectPointService.create(point, drillingInfoVo, probeInfo);
    }


    /***
     * 删除点位
     * @param ids
     * @return
     */
    @DeleteMapping("delete/{ids}")
    public JsonResult delete(@PathVariable String[] ids) {
        return projectPointService.delete(ids);
    }


    /***
     *
     * 查询点位信息
     * @return
     */
    @GetMapping("find")
    public JsonResult find(ProjectPointQuery query) {
        return projectPointService.find(query);
    }


    /***
     * 项目点位图片下载
     * @return
     */
    @PostMapping("download")
    public JsonResult download(String id) {
        return projectPointService.download(id);
    }


    /***
     * 点位信息
     * @return
     */
    @GetMapping("pointInfo")
    public JsonResult pointInfo(ProjectPointQuery query) {
        return projectPointService.pointInfo(query);
    }


    /***
     * 下载点位模板
     * @param type
     *          1:点位 钻孔信息
     *          2:点位 探槽信息
     * @return
     */
    @PostMapping("downloadTmpl/{type}")
    public JsonResult downloadTmpl(@PathVariable(value = "type") String type, HttpServletResponse response) {
        return projectPointService.downloadTmpl(type, response);
    }

    /***
     * 导入点位模板
     *          1:点位 钻孔信息
     *          2:点位 探槽信息
     * @return
     */
    @PostMapping("impexp")
    public JsonResult impexp(@RequestParam Integer projectId, @RequestParam String type, @RequestParam MultipartFile file) {
        if (!file.getOriginalFilename().endsWith(".xls") && !file.getOriginalFilename().endsWith(".xlsx")){
            return JsonResult.error("文件格式有误！");
        }
        return projectPointService.impexp(projectId, type, file);
    }

    /***
     * 上传点位文件
     * @param id
     * @param file
     * @return
     */
    @PostMapping("uploadFile")
    public JsonResult uploadFile(@RequestParam String id, @RequestParam MultipartFile file) {
        return projectPointService.uploadFile(id, file);
    }


}
